package com.explorati.interview.interview.chaptersix;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;

public class ReaderTest {

	public static void main(String[] args) {
		InputStream in = null;
		BufferedReader br = null;
		try {
			// FileInputStream文件输入流，必需
			in = new FileInputStream("e:/test/a.txt");
			// InputStreamReader对象，用来指定字符编码，非必须
			InputStreamReader ir = new InputStreamReader(in, "GBK");
			// 通过InputStream来构造BufferedReader
			br = new BufferedReader(ir);
			// 线程安全的字符串拼接类
			StringBuffer sb = new StringBuffer();
			String str = null;
			while ((str = br.readLine()) != null) {
				sb.append(str);
			}
			System.out.println("a.txt content : " + sb);
		} catch (FileNotFoundException | UnsupportedEncodingException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				br.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}
